package cn.znzz.cjm.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
@EnableWebSecurity //开启web安全配置
public class HrmAuthenConfig extends WebSecurityConfigurerAdapter {
    //配置加密解密的方式
    @Bean
    public PasswordEncoder getPasswordEncoder(){
        return new BCryptPasswordEncoder();
    }
    //配置http的安全配置

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/loginUser/login").permitAll()
                .anyRequest().authenticated()
                .and().formLogin()  //允许表单提交
                .successForwardUrl("/success")  //认证成功之后的跳转路径
                .and().logout().permitAll()  //退出放行
                .and().csrf().disable();//关闭跨站
    }
    @Override
    @Bean
    protected AuthenticationManager authenticationManager() throws Exception {
        return super.authenticationManager();
    }
}